import path, { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import vueJsx from '@vitejs/plugin-vue-jsx'
import commonjs from '@rollup/plugin-commonjs'
import esbuild from 'rollup-plugin-esbuild'

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()]
  },
  preload: {
    plugins: [externalizeDepsPlugin()]
  },
  renderer: {
    plugins: [
      vue(),
      vueJsx(),
      createSvgIconsPlugin({
        // Specify the icon folder to be cached
        iconDirs: [path.resolve(process.cwd(), 'src/renderer/src/assets/icons/svg/')],
        // Specify symbolId format
        symbolId: 'icon-[dir]-[name]'
      })
    ],
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src/renderer/src') // 路径别名
      },
      extensions: ['.js', '.vue', '.json', '.ts'] // 使用路径别名时想要省略的后缀名，可以自己 增减
    },
    css: {
      preprocessorOptions: {
        scss: {
          /* 自动引入全局scss文件 */
          additionalData: '@import "src/renderer/src/assets/styles/global.scss";'
        }
      }
    },
    optimizeDeps: {
      include: ['quill']
    },
    build: {
      //minify: false,
      commonjsOptions: {
        exclude: [],
        include: []
        //requireReturnsDefault: true
      },
      rollupOptions: {
        plugins: [commonjs({ requireReturnsDefault: false }), esbuild()]
      }
    }
  }
})
